package net.huashitong.oversee.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.utils.ObjectUtils;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.oversee.entity.ScoreSummaryTemp;
import net.huashitong.oversee.filter.ScoreSummaryFilter;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class ScoreSummaryTempDao extends StringDao<ScoreSummaryTemp> {

    public List<ScoreSummaryTemp> queryByFilterNoPage(ScoreSummaryFilter filter){
        GenericQuery query = createQuery("obj");
        if(StringUtils.isNotBlank(filter.getCheckDept())){
            query.append(" and checkDept like:checkDept").setParam("checkDept",
                    StringUtils.getLikewords(filter.getCheckDept()));
        }
        if(StringUtils.isNotBlank(filter.getCheckObject())){
            query.append(" and checkObject like:checkObject").setParam("checkObject",
                    StringUtils.getLikewords(filter.getCheckObject()));
        }
        if(StringUtils.isNotBlank(filter.getSummaryDate())){
            query.append(" and summaryDate =:summaryDate").setParam("summaryDate",
                    filter.getSummaryDate());
        }
        if(StringUtils.isNotBlank(filter.getUserId())){
            query.append(" and userId =:userId").setParam("userId",
                    filter.getUserId());
        }
        if(StringUtils.isNotBlank(filter.getBranchType())){
            query.append(" and branchType =:branchType").setParam("branchType",
                    filter.getBranchType());
        }
        if(ObjectUtils.isNotBlank(filter.getPaging())){
            if(StringUtils.isBlank(filter.getPaging().getSortCol())){
                filter.getPaging().setSortCol("rank+0");
            }
        }else{
            query.append(" ORDER BY rank+0 asc");
        }
        return query.listResult();
    }



    public List<ScoreSummaryTemp> queryScoreSummaryByIds(List<String> ids){
        GenericQuery query = createQuery("obj");
        query.append("and obj.sysId in(:ids)").setParamList("ids", ids);
        return query.listResult();
    }
}
